package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.base.enums.FlagEnum;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.soso.domain.entity.SveNoseHouseEntity;
import com.ym.soso.domain.param.PublishParam;
import com.ym.soso.domain.param.SveNoseHouseQueryParam;
import com.ym.soso.domain.param.SveNoseHouseUpdateParam;
import com.ym.soso.domain.vo.SveNoseHouseListPcVO;
import com.ym.soso.service.ISveNoseHouseSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 鼻炎馆Controller
 * 
 * @author ym
 * @date 2020-03-06
 */
@Api(tags = "pc-鼻炎馆")
@RestController
@Validated
@RequestMapping("/soso/house")
public class SveNoseHouseController extends BaseController {

    @Autowired
    private ISveNoseHouseSV sveNoseHouseSV;

    @ApiOperation("查询鼻炎馆列表")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping("/list")
    public APIResponse<PageInfo<SveNoseHouseListPcVO>> list(@Valid SveNoseHouseQueryParam queryParam) {
        PageDomain.startPage();
        queryParam.setDeleted(FlagEnum.NO.getKey());
        List<SveNoseHouseListPcVO> list = sveNoseHouseSV.selectListPC(queryParam);
        return successPage(list);
    }

    @ApiOperation("获取鼻炎馆详细信息")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping(value = "/info")
    public APIResponse<SveNoseHouseEntity> info(@RequestParam Long id) {
        SveNoseHouseEntity data = sveNoseHouseSV.selectById(id);
        return successData(data);
    }

    @ApiOperation("新增/修改鼻炎馆")
    @Log(dataBase = true, printBody = true, printQuery = false)
    @PostMapping("/update")
    public APIResponse edit(@RequestBody @Valid SveNoseHouseUpdateParam updateParam) {
        if(updateParam.getId()!=null && updateParam.getId()>0){
            sveNoseHouseSV.insertPC(updateParam);
        }else{
            sveNoseHouseSV.updateByIdPC(updateParam);
        }
        return success();
    }

    @ApiOperation("删除鼻炎馆")
    @Log(dataBase = true, printBody = true, printQuery = false)
    @PostMapping("/delete")
    public APIResponse remove(@RequestBody @Valid @NotNull Long[] ids) {
        sveNoseHouseSV.deleteByIds(ids);
        return success();
    }

    @ApiOperation("发布")
    @PostMapping("/release")
    public APIResponse release(
            @RequestBody @Valid PublishParam publishParams
    ) {
        sveNoseHouseSV.release(publishParams);
        return success();
    }
}
